package ajax;

import Impl.plateDaoImpl;
import com.alibaba.fastjson.JSON;
import entity.Plate;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet(name = "PlateAjax")
public class PlateAjax extends HttpServlet {
    plateDaoImpl plateDao = new plateDaoImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("---------正在执行PlateAjax-----------");
        ArrayList<Plate> plates = (ArrayList<Plate>) plateDao.findAllPlate();
        response.setContentType("text/html; charset=UTF-8");
        response.setCharacterEncoding("utf-8");
        String platestr = JSON.toJSONString(plates);
        System.out.println(platestr);
        response.getWriter().write(platestr);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
